IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].GetBizInfo') AND type in (N'P', N'PC'))	
DROP PROCEDURE [dbo].[GetBizInfo]	
	
GO	
	
CREATE PROCEDURE [dbo].[GetBizInfo] 	
(	
@prmBizID int = null	
)	
AS	
BEGIN	
	
Select * from Biz Where BizID = ISNULL(@prmBizID,BizID)	
	
END	
GO	
	
	
	
	
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].SaveBizInfo') AND type in (N'P', N'PC'))	
DROP PROCEDURE [dbo].[SaveBizInfo]	
	
GO	
	
CREATE PROCEDURE [dbo].[SaveBizInfo] 	
(	
@prmBizID int = null,@prmTitle varchar = null,@prmBizTypeID int = null,@prmAskingPriceLow money = null,@prmAskingPriceHigh money = null,@prmIsRelocatable bit = null,@prmIsHomeBased bit = null,@prmIsRealEstateAvial bit = null,@prmIsAssetSale bit = null,@prmIsOwnerFinancing bit = null,@prmIsAbsenteeRun bit = null,@prmIsRealEstateIncluded bit = null,@prmIsFSBO bit = null,@prmIsBrokerCoop bit = null,@prmIsTrainingAndSupportAvial bit = null,@prmIsFinancialAssistanceAvial bit = null,@prmIsParternshipAvial bit = null,@prmIsFranchise bit = null,@prmCountryID int = null,@prmStateID int = null,@prmCountyID int = null,@prmCityID int = null,@prmGrossIncome money = null,@prmCashFlow money = null,@prmEBITDA money = null,@prmFurnitureAndFixtures money = null,@prmInventory money = null,@prmYearEstablished float = null,@prmNoOfEmployees float = null,@prmReasonForSelling varchar(1000) = null,@prmListedByUserID int = null,@prmDescription varchar = null,@prmAddress1 varchar(2000) = null,@prmCreatedDT  datetime = null,@prmUpdatedDT  datetime = null,@prmIsActive bit = null,@prmIsSold bit = null,@prmViewedCounter int = null,@prmIsForBuy bit = null,@prmZip varchar(50) = null,@prmAddress2 varchar(2000) = null,@prmPostedDate  date = null,@prmInActiveDate  date = null,@prmStatus varchar(100) = null	
	
)	
AS	
BEGIN	
	
IF EXISTS (SELECT 1 from dbo.Biz  Where BizID=@prmBizID)	
BEGIN	
	UPDATE Biz SET 
	
	Title=@prmTitle,BizTypeID=@prmBizTypeID,AskingPriceLow=@prmAskingPriceLow,AskingPriceHigh=@prmAskingPriceHigh,IsRelocatable=@prmIsRelocatable,IsHomeBased=@prmIsHomeBased,IsRealEstateAvial=@prmIsRealEstateAvial,IsAssetSale=@prmIsAssetSale,IsOwnerFinancing=@prmIsOwnerFinancing,IsAbsenteeRun=@prmIsAbsenteeRun,IsRealEstateIncluded=@prmIsRealEstateIncluded,IsFSBO=@prmIsFSBO,IsBrokerCoop=@prmIsBrokerCoop,IsTrainingAndSupportAvial=@prmIsTrainingAndSupportAvial,IsFinancialAssistanceAvial=@prmIsFinancialAssistanceAvial,IsParternshipAvial=@prmIsParternshipAvial,IsFranchise=@prmIsFranchise,CountryID=@prmCountryID,StateID=@prmStateID,CountyID=@prmCountyID,CityID=@prmCityID,GrossIncome=@prmGrossIncome,CashFlow=@prmCashFlow,EBITDA=@prmEBITDA,FurnitureAndFixtures=@prmFurnitureAndFixtures,Inventory=@prmInventory,YearEstablished=@prmYearEstablished,NoOfEmployees=@prmNoOfEmployees,ReasonForSelling=@prmReasonForSelling,ListedByUserID=@prmListedByUserID,Description=@prmDescription,Address1=@prmAddress1,CreatedDT=@prmCreatedDT,UpdatedDT=@prmUpdatedDT,IsActive=@prmIsActive,IsSold=@prmIsSold,ViewedCounter=@prmViewedCounter,IsForBuy=@prmIsForBuy,Zip=@prmZip,Address2=@prmAddress2,PostedDate=@prmPostedDate,InActiveDate=@prmInActiveDate,Status=@prmStatus
	
	
	 Where BizID = @prmBizID
END	
ELSE	
BEGIN	
	 INSERT INTO Biz (BizID,Title,BizTypeID,AskingPriceLow,AskingPriceHigh,IsRelocatable,IsHomeBased,IsRealEstateAvial,IsAssetSale,IsOwnerFinancing,IsAbsenteeRun,IsRealEstateIncluded,IsFSBO,IsBrokerCoop,IsTrainingAndSupportAvial,IsFinancialAssistanceAvial,IsParternshipAvial,IsFranchise,CountryID,StateID,CountyID,CityID,GrossIncome,CashFlow,EBITDA,FurnitureAndFixtures,Inventory,YearEstablished,NoOfEmployees,ReasonForSelling,ListedByUserID,Description,Address1,CreatedDT,UpdatedDT,IsActive,IsSold,ViewedCounter,IsForBuy,Zip,Address2,PostedDate,InActiveDate,Status) 
	 Values (@prmBizID,@prmTitle,@prmBizTypeID,@prmAskingPriceLow,@prmAskingPriceHigh,@prmIsRelocatable,@prmIsHomeBased,@prmIsRealEstateAvial,@prmIsAssetSale,@prmIsOwnerFinancing,@prmIsAbsenteeRun,@prmIsRealEstateIncluded,@prmIsFSBO,@prmIsBrokerCoop,@prmIsTrainingAndSupportAvial,@prmIsFinancialAssistanceAvial,@prmIsParternshipAvial,@prmIsFranchise,@prmCountryID,@prmStateID,@prmCountyID,@prmCityID,@prmGrossIncome,@prmCashFlow,@prmEBITDA,@prmFurnitureAndFixtures,@prmInventory,@prmYearEstablished,@prmNoOfEmployees,@prmReasonForSelling,@prmListedByUserID,@prmDescription,@prmAddress1,@prmCreatedDT,@prmUpdatedDT,@prmIsActive,@prmIsSold,@prmViewedCounter,@prmIsForBuy,@prmZip,@prmAddress2,@prmPostedDate,@prmInActiveDate,@prmStatus)
END	
	
END	
GO	
	
	
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].DeleteBizInfo') AND type in (N'P', N'PC'))	
DROP PROCEDURE [dbo].[DeleteBizInfo]	
	
GO	
	
CREATE PROCEDURE [dbo].[DeleteBizInfo] 	
(	
@prmBizID int = null	
)	
AS	
BEGIN	
	
Delete from Biz Where BizID =  @prmBizID	
	
END	
GO	




IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].SaveUserInfo') AND type in (N'P', N'PC'))	
DROP PROCEDURE [dbo].[SaveUserInfo]	
	
GO	
	
CREATE PROCEDURE [dbo].[SaveUSerInfo] 	
(	
	
	@prmUserID int = null,@prmPassword varchar(1000) = null,@prmFirstName varchar(1000) = null,@prmLastName varchar(1000) = null,@prmCompanyName varchar(2000) = null,@prmContactOfficePhone varchar(50)  = null,@prmContactMobilePhone varchar(50)  = null,@prmContactEmail varchar(1000) = null,@prmLicenseNumber varchar(100) = null,@prmAddressLine1 varchar(1000) = null,@prmAddressLIne2 varchar(1000) = null,@prmCityID int = null,@prmStateID int = null,@prmCountyID int = null,@prmCountryID int = null,@prmProfilePictureExists bit = null,@prmCreatedDT  datetime = null,@prmUpdatedDT  datetime = null,@prmLoginCounter int = null,@prmZip varchar(50)  = null,@prmSecAnswer1 varchar(1000) = null,@prmSecAnswer2 varchar(1000) = null,@prmSecAnswer3 varchar(1000) = null,@prmLastLoginDateTime  datetime = null

)	
AS	
BEGIN	
	
IF EXISTS (SELECT 1 from dbo.BizUser  Where UserID=@prmUserID)	
BEGIN	
	UPDATE BizUser SET 
Password=@prmPassword,FirstName=@prmFirstName,LastName=@prmLastName,CompanyName=@prmCompanyName,ContactOfficePhone=@prmContactOfficePhone,ContactMobilePhone=@prmContactMobilePhone,ContactEmail=@prmContactEmail,LicenseNumber=@prmLicenseNumber,AddressLine1=@prmAddressLine1,AddressLIne2=@prmAddressLIne2,CityID=@prmCityID,StateID=@prmStateID,CountyID=@prmCountyID,CountryID=@prmCountryID,ProfilePictureExists=@prmProfilePictureExists,CreatedDT=@prmCreatedDT,UpdatedDT=@prmUpdatedDT,LoginCounter=@prmLoginCounter,Zip=@prmZip,SecAnswer1=@prmSecAnswer1,SecAnswer2=@prmSecAnswer2,SecAnswer3=@prmSecAnswer3,LastLoginDateTime=@prmLastLoginDateTime


	
	
	
	
	 Where UserID = @prmUserID
END	
ELSE	
BEGIN	
	 INSERT INTO BizUser (UserID,Password,FirstName,LastName,CompanyName,ContactOfficePhone,ContactMobilePhone,ContactEmail,LicenseNumber,AddressLine1,AddressLIne2,CityID,StateID,CountyID,CountryID,ProfilePictureExists,CreatedDT,UpdatedDT,LoginCounter,Zip,SecAnswer1,SecAnswer2,SecAnswer3,LastLoginDateTime
) 
	 Values (@prmUserID,@prmPassword,@prmFirstName,@prmLastName,@prmCompanyName,@prmContactOfficePhone,@prmContactMobilePhone,@prmContactEmail,@prmLicenseNumber,@prmAddressLine1,@prmAddressLIne2,@prmCityID,@prmStateID,@prmCountyID,@prmCountryID,@prmProfilePictureExists,@prmCreatedDT,@prmUpdatedDT,@prmLoginCounter,@prmZip,@prmSecAnswer1,@prmSecAnswer2,@prmSecAnswer3,@prmLastLoginDateTime
)
END	
	
END	
GO

/****** Object:  StoredProcedure [dbo].[deleteUserInfo]    Script Date: 02/13/2015 15:34:02 ******/

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].deleteUserInfo') AND type in (N'P', N'PC'))	
DROP PROCEDURE [dbo].[deleteUserInfo]	
	
GO	

CREATE PROCEDURE [dbo].[deleteUserInfo] 
(
@prmUserId  int = null
)
AS
BEGIN

Delete from BizUser Where UserId =  @prmUserId

END

